/**
* @Author: Zhengfeng.Yao
* @Date:   2017-01-23 14:12:23
* @Last modified by:   Zhengfeng.Yao
* @Last modified time: 2017-02-09 14:49:09
*/

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'mobx-react';
import { browserHistory, hashHistory, Router } from 'react-router'
import App from './app';
import ConfigureStore from './configureStore';
import routes from './routes'

function getQueryString(name) {
  const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);
  const r = window.location.search.substr(1).match(reg);

  if (r != null) {
		return unescape(r[2]);
  }
  return null;
}

const stores = ConfigureStore();

const MOUNT_NODE = document.getElementById('app');

const isDebug = getQueryString('debugging');
if (__DEV__ || isDebug) {
  window.appStore = stores.appStore;
	const enableLogging = require('mobx-logger').default;
	enableLogging({
    predicate: () => true,
    action: true,
    reaction: true,
    transaction: true,
    compute: true
	});
}

ReactDOM.render(
  <Provider
     {...stores}
   >
    <Router history={hashHistory} routes={routes} />
  </Provider>,
  MOUNT_NODE
);
